package com.dianzi.certification.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dianzi.certification.entity.User;
import com.dianzi.certification.mapper.UserMapper;
import com.dianzi.certification.service.AuthService;
import com.dianzi.certification.vo.R;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author copa
 * @createDate 2022-03-08 0:14
 * @function
 */
@Service
public class AuthServiceImpl implements AuthService {

    @Resource
    private UserMapper userMapper;

    @Override
    public R<User> findByName(String username) {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper();
        wrapper.eq(StringUtils.isNotBlank(username), User::getName, username);
        User user = userMapper.selectOne(wrapper);
        if (Objects.isNull(user)) {
            return R.error();
        }
        return R.success(user);
    }
}
